package com.sjm.suchbear.easymap.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sjm.suchbear.easymap.Model.GDmodel;
import com.sjm.suchbear.easymap.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Suchbear on 2018/3/14.
 */

public class SearchAdapter extends BaseAdapter {

    private Context context;
    private List<GDmodel.PoisBean> poiList;


    public SearchAdapter(Context context, List<GDmodel.PoisBean> poiList) {
        this.context = context;
        this.poiList = poiList;
    }

    @Override
    public int getCount() {
        if (poiList != null) {
            return poiList.size();
        } else {
            return 0;
        }

    }

    @Override
    public Object getItem(int position) {
        return poiList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_searchresult, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        GDmodel.PoisBean poiInfo = poiList.get(position);
        viewHolder.tvSearchName.setText(poiInfo.getName());
        viewHolder.tvSearchAddress.setText(poiInfo.getLocation());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_SearchName)
        TextView tvSearchName;
        @BindView(R.id.tv_SearchAddress)
        TextView tvSearchAddress;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
